package com.hrmsys.action;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.hrmsys.model.Leave;
import com.hrmsys.model.User;
import com.hrmsys.service.LeaveService;
import com.opensymphony.xwork2.ActionContext;

public class LeaveAction extends BaseAction {

	private LeaveService leaveService;

	private String start,limit;
	
	private Leave leave;
	
	private String ids;
	private String id;
	
	private String status,approveContent;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1733092683654570682L;
	
	public void list(){
		String all = leaveService.getAll(start, limit);
		this.out(all);
	}

	public void saveOrUpdate(){
		User user = (User)ActionContext.getContext().getSession().get("user");
		leave.setLeaveAccount(user.getEmployee().getEmpId());
		leave.setLeaveUser(user.getUserName());
		leave.setApproveStatus("0");
		//获得2000-01-01 的Date对象
		DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
		Date myDate1 = null;
		try {
			myDate1 = dateFormat1.parse("2000-01-01");
		} catch (ParseException e) {
			e.printStackTrace();
		}
		leave.setApproveTime(myDate1);
		String msg = leaveService.save(leave);
		this.out("{success: true, msg: '"+msg+"'}");
	}
	
	public void approveLeave(){
		User user = (User)ActionContext.getContext().getSession().get("user");
		leave.setApproveUser(user.getUserName());
		leave.setApproveStatus(status);
		String msg = leaveService.save(leave);
		this.out("{success: true, msg: '"+msg+"'}");
	}
	
	public void delete(){
		String msg = leaveService.delete(this.getIds());
		this.out("{success: true, msg: '"+msg+"'}");
	}
	
	public void intoUpdate(){
		String json = leaveService.listById(id);
		this.out(json);
	}
	
	
	
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 * @return the ids
	 */
	public String getIds() {
		return ids;
	}

	/**
	 * @param ids the ids to set
	 */
	public void setIds(String ids) {
		this.ids = ids;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the leaveService
	 */
	public LeaveService getLeaveService() {
		return leaveService;
	}

	/**
	 * @param leaveService the leaveService to set
	 */
	public void setLeaveService(LeaveService leaveService) {
		this.leaveService = leaveService;
	}

	/**
	 * @return the start
	 */
	public String getStart() {
		return start;
	}

	/**
	 * @param start the start to set
	 */
	public void setStart(String start) {
		this.start = start;
	}

	/**
	 * @return the limit
	 */
	public String getLimit() {
		return limit;
	}

	/**
	 * @param limit the limit to set
	 */
	public void setLimit(String limit) {
		this.limit = limit;
	}

	/**
	 * @return the leave
	 */
	public Leave getLeave() {
		return leave;
	}

	/**
	 * @param leave the leave to set
	 */
	public void setLeave(Leave leave) {
		this.leave = leave;
	}

	public String getApproveContent() {
		return approveContent;
	}

	public void setApproveContent(String approveContent) {
		this.approveContent = approveContent;
	}
	
	
}
